import {Storage, Cache} from '../../common/utils/Common';

import router from '@ohos.router';

export default {
    data: {
        // navbar 播放需要的参数
        currentPlay: {
            id: 0,
            title: '留言',
            cover: 'https://p1.music.126.net/8g2Pn9Xw1m7cFhxOlc3BMg==/109951167875709379.jpg?param=140y140',
            singer: '张学友',
            // 播放状态
            playing: false
        },
        // 用户信息
        userMsg: {
            nickname: '',
            avatar: '',
            desc: '',
        },
        // 用户喜爱音乐
        mySelfMusics: [
            {
                cover: 'https://p1.music.126.net/ORu6eHfwBR_TPHzGrO2ZsA==/109951165306881115.jpg?param=140y140',
                title: '侧田',
                singer: '80首',
                desc: '听了 1586 次',
                play: false
            },
            {
                cover: 'https://p1.music.126.net/996rt3pviChd-Z86JxVqmQ==/109951165630302115.jpg?param=140y140',
                title: '华语',
                singer: '864首',
                desc: '听了 1527 次',
                play: false
            }
        ]
    },
    onInit() {
        let cache;
        if (!(cache = this.$app.$def.cache)) {
            this.$app.$def.cache = new Cache();
            cache = new Cache();
        }
    },
    /**
     * 播放音乐 由 music_item 传入
     * @param val 音乐信息
     */
    playMusic(val) {
        // 2. 父组件接收了 music_item 传入的数据并将其列为正在播放的音乐，返回给 bottom_nav 进行同步
        let data = val.detail;
        Object.assign(this.currentPlay, data);
        // 在数组中开放 play
        this.searchPlayFunc(true);
    },
    /**
     * 停止音乐，由 music_item 传入
     * @param val 音乐信息
     */
    stopMusic(val) {
        let data = val.detail;
        Object.assign(this.currentPlay, data);
        this.searchPlayFunc(false);
    },
    goMusicList(mode) {
      router.push({
          url: 'pages/music_list/music_list',
          params: {mode: mode}
      })
    },
    /** 获取用户信息 */
    async getUserMsg() {
        let storage = new Storage('user');
        let data = await storage.get('userMsg');
        if (data) {
            let json = JSON.parse(data);
            Object.assign(this.userMsg, json.data);
        }
    },

    /**
     * 当使用 nav 进行播放。
     * @param val 当前播放音乐的 id
     */
    navPlay(val) {
        this.currentPlay.id = val.detail;
    },
    /**
     * 当使用 nav 停止播放。
     * @param val 当前播放音乐的 id
     */
    navStop(val) {
        this.currentPlay.id = val.detail;
    },
/*    async getMsg() {
        let data = {
            "params": "nheHBVTaTFx7RKULyRFv8ADnYJklPVv1ecDQ+k/tbwAlhKCceytozO6FTscEjDO0B+PBQwxvmRHFWItkN0FNUrBGDFnkdWUHlFlZVuSbjsI0fo9GeZvp98vXREJF0OPIccFAbjYayXcZ6+AQZ4ueKPpNejqqdeGqBdaIezkucAfnHHPftiQ6N01ICDp6LHkLXr+Q52ShOHLvQJOkXu0o5gi9LzfMps3g9qgYiI4vP4k=",
            "encSecKey": "4be9e5c902aa73e5795c52fb5e2c73a816f8f108dc6fcc23a952cb5be339c4a4819b91970f885aca28a87504fa2bd5981ca2a89425f202d8e6e1021359298e9122f369040e4cefec807dfc835537df69b9a6b08dffd07f1930109410b38704d2d6ae1e8a4f11576920f653b223b71640363a79e9a3a7aca866457ee44fdf4415"
        };
        let header = {
            "cookie": "P_INFO=18925800360|1665121389|1|netease_buff|00&99|null&null&null#gud&441900#10#0|&0|null|18925800360; _ntes_nnid=f3c4406ffeb32a01cbcfb089dfc0a0f0,1666919222354; _ntes_nuid=f3c4406ffeb32a01cbcfb089dfc0a0f0; NMTID=00OkeFVI2VwR6JlaUTzkNtbqSCv2dsAAAGEHCDDcg; WEVNSM=1.0.0; WNMCID=vykfnn.1666919222945.01.0; WM_TID=YuAUg6cTp8BFUABQQQfBdBLkWUH0bY3p; __snaker__id=ZpFRMjXIIyJbjM11; gdxidpyhxdE=ps4vwwz89BNfptKj3tmM88NAxtmwhRmN79ohxU1nnuaj%2F1qE8cuAYiL1hUCzlU2rz3oz%2BjkT2T2PdJfexxHtGlfBpOfQ%5CIXh%5CEvE%2Fm260Y9oqwiHYB5w97Z62UpYxtbO8SJeekjTU43KWS6OOuVkwYJxZKHHsQHu5Q01BraiIXH5Anfa%3A1666973750762; YD00000558929251%3AWM_NI=occxSflMkH9HzHgK6PoQKvq4zUu00PnjzHjzBN8Ny%2FltO40ITO4kwQWdmp8acNDfUQjbO1kNhnxZd2kGWWQ1JEkSfyr6iw7DyCHoT%2BKXNw51n2zr5VQtUiFwL4%2BblV%2FbQWM%3D; YD00000558929251%3AWM_NIKE=9ca17ae2e6ffcda170e2e6eea9c77490bfad8cb44797eb8ea3c15b868b8facc17086bafabbf665988a8c93cd2af0fea7c3b92aadbdad99d26eb093a5a9bc44ba98a9acb55cad8f8597f440ba8bbbd1b35caeb6b6a9e9728292f8affc25b0ac81d5b3439891fc8cf65b95bca391bb6ba1928c87d85baabe81d2ea46acb2b8bbe73aa99999b8d43b8a9ba5b4e573b2eaa798b650bb9d8890d72189888298b83baeeeb693b85e93ac9b8ac57d90ece583ef5eedbe9fb8d037e2a3; YD00000558929251%3AWM_TID=3Vn1PwlN%2FSdFFEAAQQeFdVP6YktHVXqI; __csrf=65a2c295becb81313f99f7008a100614; MUSIC_U=7b7eac8c37dd322c5ebeee8de4fb1c715e120563e59917bbff103da6309f33511e8907c67206e1ed8dff4884a909dc82a1bddd23dbc9cbe3aaf7197a3ac1dc2cc9bf60075ed4bf01d4dbf082a8813684; ntes_kaola_ad=1; _iuqxldmzr_=32; WM_NI=AN0FLqtSilUBMANbUXH0CwNbSIlGidsptqIWf%2BKJvTlNkn6Y9GWUaB5RGimyBZYq1FThhFAMRm3MkYRCqaXTpCyt6KqD8fCJYXcLi9SbMwwLdY5jSJrRHHarIsMQ1%2Bz6ck8%3D; WM_NIKE=9ca17ae2e6ffcda170e2e6eedae96987879798b66e89a88ea3d15f939a9b82c54296b8888afb7cacf5a28df72af0fea7c3b92a839200a7cf7bb88da78dd84a8f9f8283d8548cf08d98cd6a9197a4a8ec70b1b0bc92cc5da6f585abf560b092a58fb553fb9999b6e44af78e898af07382869792b44e98b8a8a7c44792b3fdaeea53929dbf82db60b49db795b541b39cf887c2429b88adadec3391be8398f648a887fb8bd242b28e88a9e47a8bad83b2b421baeaad8cbb37e2a3; JSESSIONID-WYYY=lWn5B5egX0aCVKqjOP6URBwQ7odPFvmXdkbqQ2EWprr%2BuuY6bYQrCccv%5CSdgWpbsF8ikDpGqVwoj24QMe6r%5CXhIsqtFNGDN4%2Ft0JOIUv1qWr7ymIMql%2Fh5qO4pCMO5fab5X03geODW6rYvmjS6vclyOw0QQwlsq6QAFSoHEffw8kPfIQ%3A1667045279196",
            "Content-Type": "application/x-www-form-urlencoded"
        }
        let res = await Request.build('/weapi/user/playlist?csrf_token=65a2c295becb81313f99f7008a100614', header)
            .customer('https://music.163.com')
            .post(data);
    }*/
}
